package jrain.fw.json.fastjson;

import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;

import jrain.fw.core.json.JsonService;
import jrain.fw.core.service.Service;
import jrain.fw.core.service.ServiceConst;

@Service(group = ServiceConst.S_JSON_SERVICE, module = ServiceConst.M_JSON)
public class JsonFastJsonService implements JsonService {

	@Override
	public String toJson(Object object) {
		return JSON.toJSONString(object);
	}

	@Override
	public String toJson(Object object, Map<String, Object> cfg) {
		return JSON.toJSONString(object);
	}

	@Override
	public List<Object> toList(String json) {
		return JSON.parseArray(json);
	}

	@Override
	public List<Object> toList(String json, Map<String, Object> cfg) {
		return JSON.parseArray(json);
	}

	@Override
	@SuppressWarnings("unchecked")
	public Map<String, Object> toMap(String json) {
		return JSON.parseObject(json, Map.class);
	}

	@Override
	@SuppressWarnings("unchecked")
	public Map<String, Object> toMap(String json, Map<String, Object> cfg) {
		return JSON.parseObject(json, Map.class);
	}

	@Override
	public <T> T toObject(String json, Class<T> t) {
		return JSON.parseObject(json, t);
	}

	@Override
	public <T> T toObject(String json, Class<T> t, Map<String, Object> cfg) {
		return JSON.parseObject(json, t);
	}

}
